-
Notifications
You must be signed in to change notification settings - Fork 825
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature(views): move views registration to MeterProvider constructor #3066
feature(views): move views registration to MeterProvider constructor #3066
Conversation
Codecov Report
@@ Coverage Diff @@
## main #3066 +/- ##
==========================================
+ Coverage 93.08% 93.09% +0.01%
==========================================
Files 188 188
Lines 6261 6256 -5
Branches 1323 1319 -4
==========================================
- Hits 5828 5824 -4
+ Misses 433 432 -1
|
cca5c73
to
a44657e
Compare
experimental/packages/opentelemetry-sdk-metrics-base/src/MeterProvider.ts
Outdated
Show resolved
Hide resolved
export type ViewOptions = { | ||
// View | ||
/** | ||
* If not provided, the Instrument name will be used by default. This will be used as the name of the metrics stream. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, after this change, the options object does contain an instrumentName
that can be confused with the term "Instrument name" in this statement.
* If not provided, the Instrument name will be used by default. This will be used as the name of the metrics stream. | |
* If not provided, the original Instrument name will be used by default. This will be used as the name of the metrics stream. |
Or can we update the instrumentName
to be selectInstrumentName
or something else to clarify that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for pointing this out. I updated the documentation in 59e69ae. 🙂
I hope that the documentation is sufficient, but I'm not opposed to changing the name too.
experimental/packages/opentelemetry-sdk-metrics-base/src/view/View.ts
Outdated
Show resolved
Hide resolved
constructor(viewOptions: ViewOptions) { | ||
// If no criteria is provided, the SDK SHOULD treat it as an error. | ||
// It is recommended that the SDK implementations fail fast. | ||
if (isSelectorProvided(viewOptions)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by this assertion. Views without name specified should be allowed to not set instrument selection criteria. Like:
new View({
aggregation: DEFAULT_AGGREGATION
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I fully agree, I was quite surprised as well when I re-read the spec and found that this should not be allowed.
Here it states, in context of instrument selection criteria that:
If no criteria is provided, the SDK SHOULD treat it as an error. It is
recommended that the SDK implementations fail fast. Please refer to Error
handling in OpenTelemetry for the general guidance.
That being said: it is not completely impossible to get the same outcome as before. It now requires providing a wildcard instrumentName
like so:
new View({
aggregation: DEFAULT_AGGREGATION,
instrumentName: '*'
});
So even with this change to make it comply with the spec, the functionality is still retained, but I agree that this specific case is more confusing now than it was before. 😕
experimental/packages/opentelemetry-sdk-metrics-base/src/view/View.ts
Outdated
Show resolved
Hide resolved
this.description = config?.description; | ||
this.aggregation = config?.aggregation ?? Aggregation.Default(); | ||
this.attributesProcessor = config?.attributesProcessor ?? AttributesProcessor.Noop(); | ||
constructor(viewOptions: ViewOptions) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find that isViewOptionsEmpty
is no longer applied on creating the views. Is there any specific reason for removing that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by this change. IMO, empty view configuration is not meaningful -- it's just the default view and doesn't need to be added anyways, whilst empty view selection criteria are helpful in adding a custom default view. Would you mind elaborating on this change? |
I can see that this is an odd change. It comes from a misunderstanding I had when implementing it in #2820. More details can be found in this comment here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code-wise LGTM. Still not sure about allowing empty views. But this is a trivial behavior, I'm not going to block this from landing.
Thank you for your review! 🙂 If you like I can open a discussion issue and maybe we can add it back in. I'm actually of the same opinion as you are on this. When I first implemented this check, it was a natural thing to check if the view is empty. In this PR I allowed empty views again as the spec does not explicitly prohibit it. Other SDKs (relevant code for Java, Python and .NET) also allow empty views, so we would be going against the grain on this. |
An empty view is never selected right? Shouldn't they just be dropped? Maybe i'm misunderstanding |
Yes, it is effectively a no-op. The changes here have the effect that creating empty views does not throw anymore. Edit: formatting. |
We have two conditions here:
Before this change, for the above conditions, we have:
With this change, the conditions are on the contrary:
Does the previous behavior of (2) sound ambiguous on whether it means "select all" or "select nothing" to you? If so, maybe the change in this PR made (2) more precise. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM I think this is way less likely to be misconfigured.
Can you update the README also?
experimental/packages/opentelemetry-sdk-metrics-base/src/MeterProvider.ts
Outdated
Show resolved
Hide resolved
experimental/packages/opentelemetry-sdk-metrics-base/src/MeterProvider.ts
Outdated
Show resolved
Hide resolved
experimental/packages/opentelemetry-sdk-metrics-base/src/view/View.ts
Outdated
Show resolved
Hide resolved
Added a simple example to the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still LGTM
I wonder if that would not create another problem for end user that want to change aggregation for auto instrumentations where they need to do it before importing instrumentations (which looks like the same issue for module monkey patching). Now user will need to have to construct trace and metrics provider, add view on metrics and then import instrumentations ? PS: @pichlermarc you will need to rebase your branch |
@vmarchaud yes, but since One of my motivations in this PR is that it allows us to add an I rebased the branch. 🙂 |
Yeah i understood this too with your PR, i though initially that adding views would reconfigure instrument.
Cool to know its the end goal ! I was already imagining end users complaining that this isn't friendly so thats why i brought the subject :) |
Previously failing test seems to be related to |
@dyladan since you had nits since last review i'll let you merge if you are still good |
Which problem is this PR solving?
When
create<instrument_name_here>()
is called beforeaddView()
, the View is not applied to the instrument.Having
addView()
on theMeterProvider
the gives the wrong impression that this can be done after creating instruments.This PR moves the functionality provided by
addView()
to the MeterProvider constructor. This is how most SDKs (Python, Java, .NET) handle this today.This makes it clear that views have to be created before creating instruments (as no Meter, and therefore no Instrument can be created without a MeterProvider), and brings us in line with other SDKs.
Also fixes a specification inconsistency where views would allow empty instrument/meter selectors, but not empty view options (see spec here).
Fixes #3056
Short description of the changes
View
registration to the constructorView
class.ViewOptions
andSelectorOptions
into one interface to reduce nesting when creatingView
sname
,aggregation
,description
,attributeKeys
)instrumentName
,instrumentType
,meterName
,meterSchemaUrl
,meterVersion
)Type of change
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Checklist: